import React, {Component} from 'react';
import { hashHistory } from 'react-router';
import { Icon, Button, Table, Input, Select, Modal, Form, message } from 'antd';
import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux'; 
import { connect } from 'react-redux';
import '@/common/css/index.less'

import { updateProposal } from '../action';
import BreadcrumbBar from '@/common/BreadcrumbBar';//面包屑组件
import ToolBar from '@/common/ToolBar';//操作栏组件
import ViewSuggestForm from './ViewSuggestForm'
import EditSuggestForm from './EditSuggestForm';

const mapStoreStateToProps = state => ({
	suggestState: state.suggest
});

const mapDispatchToProps = dispatch => bindActionCreators({
	onUpdateProposal: updateProposal
}, dispatch);

class ViewSuggest extends Component {
    constructor(props){
        super(props);
        this.state = {
            edit: false
        }

    }

    componentDidMount = () => {
        // console.log("记录id",this.props.params.id)
    }

    componentWillUnmount = () => {
		this.setState = (state,callback)=>{
          return;
        };
	}

    // componentWillReceiveProps = (nextProps) => {
    //     let _data = nextProps.suggestState.data;
    // }

    showEdit = () => {
        this.setState({ edit: true })
    }

    goBack = () => {
        hashHistory.goBack();
    }

    render(){
        
        // console.log("data",this.props.suggestState.data)
        const data = this.props.suggestState.data;
        return (
            <div>
                <BreadcrumbBar one="员工建议" two="我的建议" three="查看"/>
                <ToolBar>
                    <Button onClick={this.showEdit}>编辑</Button>
                    <Button>填写意见</Button>
                    <Button>查看流程</Button>
                    <Button>评价/查看评价</Button>
					<Button onClick={this.goBack}>返回</Button>
                </ToolBar>
                <div className="content-layer">
                    { !this.state.edit ? <ViewSuggestForm /> : <EditSuggestForm/> }
                </div>
            </div>
        )
    }
}

ViewSuggest.PropTypes = {
    suggestState: PropTypes.object.isRequired,
    onUpdateProposal: PropTypes.func.isRequired
}

export default connect(mapStoreStateToProps,mapDispatchToProps)(ViewSuggest);